package cn.template.serve_project.service.impl;

import cn.template.serve_project.entity.Role;
import cn.template.serve_project.mapper.RoleMapper;
import cn.template.serve_project.service.RoleService;
import cn.template.serve_project.vo.role.RoleVO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 角色(Role)表服务实现类
 *
 */
@Service("roleService")
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {

    private final  RoleMapper roleMapper;
    RoleServiceImpl(RoleMapper roleMapper){
        this.roleMapper = roleMapper;
    }

    /**
     * 获取所有的角色
     *
     * @return 角色列表
     */
    @Override
    public List<RoleVO> selectAll() {
        LambdaQueryWrapper<Role> wrapper = new LambdaQueryWrapper<>();
        wrapper.select(Role::getRoleId,Role::getRoleName,Role::getRoleValue);
        List<Role> roles = roleMapper.selectList(wrapper);
        List<RoleVO> result = new ArrayList<>();
        roles.forEach(s->{
            RoleVO data = new RoleVO();
            BeanUtils.copyProperties(s,data);
            result.add(data);
        });
        return result;
    }
}

